@gradingform @gradingform_metaagm
Feature: Metacriteria's grading forms can be managed as usual.
  In order to make Meta grading form ready to use
  As a teacher
  I need to define one or more grading forms in metacriteria.

  Background:
    Given the following "users" exist:
      | username | firstname | lastname | email            |
      | teacher1 | Teacher   | 1        | teacher1@asd.com |
    And the following "courses" exist:
      | fullname | shortname | format |
      | Course 1 | C1        | topics |
    And the following "course enrolments" exist:
      | user     | course | role           |
      | teacher1 | C1     | editingteacher |
    And I log in as "teacher1"
    And I follow "Course 1"
    And I turn editing mode on
    And I add a "Assignment" to section "1" and I fill the form with:
      | Assignment name | Test assignment 1 name      |
      | Description     | Test assignment description |
      | Grading method  | Meta AGM                    |

  Scenario: Leave metacriterion form draft
    Given I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Rubric"
    When I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 rubric  |
      | Description | Rubric test description |
    And I define the following rubric:
      | Rubric Criterion 1 | Level 11 |  1 | Level 12 | 20 | Level 13 | 40 | Level 14 | 50 |
      | Rubric Criterion 2 | Level 21 | 10 | Level 22 | 20 | Level 23 | 30 |
      | Rubric Criterion 3 | Level 31 |  5 | Level 32 | 20 |
    And I press "Save as draft"
    Then I should see "The advanced grading form is not ready at the moment"
    When I follow "Advanced grading"
    Then I should see "Draft"
    When I go to "Test assignment 1 name" advanced grading definition page
    And I edit a definition for metacriterion "Test metacriterion 1"
    And I press "Save rubric and make it ready"
    And I follow "Advanced grading"
    Then I should see "Ready for use"

  Scenario: Define a rubric
    Given I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Rubric"
    When I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 rubric  |
      | Description | Rubric test description |
    And I define the following rubric:
      | Rubric Criterion 1 | Level 11 |  1 | Level 12 | 20 | Level 13 | 40 | Level 14 | 50 |
      | Rubric Criterion 2 | Level 21 | 10 | Level 22 | 20 | Level 23 | 30 |
      | Rubric Criterion 3 | Level 31 |  5 | Level 32 | 20 |
    And I press "Save rubric and make it ready"
    Then I should see "Rubric Criterion 1"
    And I should see "Rubric Criterion 2"
    And I should see "Rubric Criterion 3"

  Scenario: Define a marking guide
    Given I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    When I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 guide  |
      | Description | Guide test description |
    And I define the following marking guide:
      | Guide Criterion 1 | For Students 1... | For Markers 1... | 30 |
      | Guide Criterion 2 | For Students 2... | For Markers 2... | 70 |
    And I press "Save marking guide and make it ready"
    Then I should see "Guide Criterion 1"
    And I should see "Guide Criterion 2"

  Scenario: Change the metacriterion active grading method
    Given I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    And I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 guide  |
      | Description | Guide test description |
    And I define the following marking guide:
      | Guide Criterion 1 | For Students 1... | For Markers 1... | 30 |
      | Guide Criterion 2 | For Students 2... | For Markers 2... | 70 |
    And I press "Save marking guide and make it ready"
    When I change metacriterion "Test metacriterion 1" grading method to "Rubric"
    And I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 rubric  |
      | Description | Rubric test description |
    And I define the following rubric:
      | Rubric Criterion 1 | Level 11 |  1 | Level 12 | 20 | Level 13 | 40 | Level 14 | 50 |
      | Rubric Criterion 2 | Level 21 | 10 | Level 22 | 20 | Level 23 | 30 |
      | Rubric Criterion 3 | Level 31 |  5 | Level 32 | 20 |
    And I press "Save rubric and make it ready"
    Then I should see "Rubric Criterion 1"
    And I should see "Rubric Criterion 2"
    And I should see "Rubric Criterion 3"
    When I change metacriterion "Test metacriterion 1" grading method to "Marking guide"
    Then I should see "Guide Criterion 1"
    And I should see "Guide Criterion 2"

  Scenario: Delete defined form
    Given I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    And I create a definition for metacriterion "Test metacriterion 1"
    And I set the following fields to these values:
      | Name        | Metacriterion 1 guide  |
      | Description | Guide test description |
    And I define the following marking guide:
      | Guide Criterion 1 | For Students 1... | For Markers 1... | 30 |
      | Guide Criterion 2 | For Students 2... | For Markers 2... | 70 |
    And I press "Save marking guide and make it ready"
    When I delete the grading form of metacriterion "Test metacriterion 1"
    And I wait to be redirected
    Then I should see "The advanced grading form is not ready at the moment"
    And I follow "Advanced grading"
    And I should see "Draft"